package com.ruoyi.dgw.service.impl;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.mapper.SysDeptMapper;
import com.ruoyi.system.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.dgw.mapper.CowShedMapper;
import com.ruoyi.dgw.domain.CowShed;
import com.ruoyi.dgw.service.ICowShedService;

/**
 * 牛棚Service业务层处理
 *
 * @author ll
 * @date 2021-12-31
 */
@Service
public class CowShedServiceImpl implements ICowShedService {
    @Autowired
    private CowShedMapper cowShedMapper;
    @Autowired
    private SysUserMapper sysUserMapper;
    @Autowired
    private SysDeptMapper sysDeptMapper;

    /**
     * 查询牛棚
     *
     * @param cowShedId 牛棚主键
     * @return 牛棚
     */
    @Override
    public CowShed selectCowShedByCowShedId(String cowShedId) {
        return cowShedMapper.selectCowShedByCowShedId(cowShedId);
    }

    /**
     * 查询牛棚列表
     *
     * @param cowShed 牛棚
     * @return 牛棚
     */
    @Override
    public List<CowShed> selectCowShedList(CowShed cowShed) {
        return cowShedMapper.selectCowShedList(cowShed);
    }

    /**
     * 新增牛棚
     *
     * @param cowShed 牛棚
     * @return 结果
     */
    @Override
    public int insertCowShed(CowShed cowShed) {
        int userId = sysUserMapper.queryUserById(cowShed.getUserId(), cowShed.getUserName());
        cowShed.setUserId(String.valueOf(userId));
        int dept = sysDeptMapper.selectDeptByName(cowShed.getDeptId());
        cowShed.setDeptId(String.valueOf(dept));
        cowShed.setCreateTime(DateUtils.getNowDate());
        return cowShedMapper.insertCowShed(cowShed);
    }

    /**
     * 修改牛棚
     *
     * @param cowShed 牛棚
     * @return 结果
     */
    @Override
    public int updateCowShed(CowShed cowShed) {
        return cowShedMapper.updateCowShed(cowShed);
    }

    /**
     * 批量删除牛棚
     *
     * @param cowShedIds 需要删除的牛棚主键
     * @return 结果
     */
    @Override
    public int deleteCowShedByCowShedIds(String[] cowShedIds) {
        return cowShedMapper.deleteCowShedByCowShedIds(cowShedIds);
    }

    /**
     * 删除牛棚信息
     *
     * @param cowShedId 牛棚主键
     * @return 结果
     */
    @Override
    public int deleteCowShedByCowShedId(String cowShedId) {
        return cowShedMapper.deleteCowShedByCowShedId(cowShedId);
    }
}
